package com.sskj.mine.ui.fragment;


import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bulong.rudeness.RudenessScreenHelper;
import com.shizhefei.mvc.MVCCoolHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.adapter.slimadapter.SlimAdapter;
import com.sskj.common.adapter.slimadapter.SlimInjector;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseFragment;
import com.sskj.lib.mvchelper.ModelRx2DataSource;
import com.sskj.mine.R;
import com.sskj.mine.R2;
import com.sskj.mine.bean.TeamBean;
import com.sskj.mine.presenter.TeamFragmentPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;


/**
 * 间推、直推
 */
@Route(path = RConfig.MINE_FRAGMENT_TEAM)
public class TeamFragment extends BaseFragment<TeamFragmentPresenter> {
    @BindView(R2.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R2.id.coolRefreshView)
    CoolRefreshView coolRefreshView;
    @Autowired
    boolean isDirect;//是否直推 间推


    @Override
    protected int getLayoutId() {
        return R.layout.mine_fragment_team;
    }

    @Override
    public TeamFragmentPresenter getPresenter() {
        return new TeamFragmentPresenter();
    }

    @Override
    protected void initView() {
        ARouter.getInstance().inject(this);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(getActivity())
                .setPaintWidth((int) RudenessScreenHelper.pt2px(App.INSTANCE, 20))
                .setDividerColor(ContextCompat.getColor(App.INSTANCE, R.color.transparent))
        );
        SlimAdapter slimAdapter = SlimAdapter.create().register(R.layout.mine_recy_item_team, new SlimInjector<TeamBean>() {
            @Override
            public void onInject(TeamBean data, IViewInjector injector, List payloads) {

                injector
                        .text(R.id.tvUID, data.getAccount())
                        .text(R.id.tvAccount, data.getPhone())
                        .text(R.id.tvTime, data.getCreated_at())
                ;
            }
        }).attachTo(recyclerView).updateData(new ArrayList());

        ModelRx2DataSource<TeamBean> dataSource = new ModelRx2DataSource<>((ModelRx2DataSource.OnLoadSource<TeamBean>)
                page -> mPresenter.getData(page + "", isDirect), 10);
        MVCCoolHelper<List<TeamBean>> mvcHelper = new MVCCoolHelper<>(coolRefreshView);
        mvcHelper.setDataSource(dataSource);
        mvcHelper.setAdapter(slimAdapter);
        mvcHelper.refresh();
    }
}
